package yw.nmh.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import yw.nmh.penInfo.dto.PenDTO;
import yw.nmh.penInfo.dto.PenListDTO;
import yw.nmh.penInfo.dto.PenUpdateDTO;
import yw.nmh.penInfo.vo.PenVO;
import yw.nmh.result.R;
import yw.nmh.service.PenService;

@RestController
@Slf4j
@Tag(name = "圈舍", description = "圈舍管理相关接口")
@RequestMapping("/pen")
public class PenController {
    @Resource
    private PenService penService;
    @Operation(summary = "添加圈舍", description = "添加圈舍接口")
    @PostMapping("/addPen")
    public R addPen(@RequestBody PenDTO penDTO){
        return penService.addPen(penDTO)?R.OK("添加圈舍成功"):R.FAIL("已存在此圈舍");
    }

    @Operation(summary = "修改圈舍状态", description = "修改圈舍状态接口")
    @PutMapping("/updatePenStatus")
    public R updatePenStatus(@RequestParam Integer penId){
        return penService.updateStatus(penId)?R.OK("修改状态成功"):R.FAIL("修改状态失败");
    }

    @Operation(summary = "修改圈舍", description = "修改圈舍接口")
    @PutMapping("/updatePen")
    public R updatePen(@RequestBody PenUpdateDTO penUpdateDTO){
        return penService.updatePen(penUpdateDTO)?R.OK("修改成功"):R.FAIL("修改失败");
    }

    @Operation(summary = "查询圈舍", description = "查询圈舍接口")
    @PostMapping("/listPen")
    public R listPen(@RequestBody PenListDTO penListDTO){
        Page<PenVO> penVOPage = penService.listPen(penListDTO);
        return R.OK(penVOPage);
    }
}
